package com.stu.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author zy
 * @date 2025/3/4 10:39
 */
public class ConnectionUtil {
    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName(ReadDBParamUtil.getDriverName());

            conn = DriverManager.getConnection(ReadDBParamUtil.getUrl(),
                    ReadDBParamUtil.getUserName(),
                    ReadDBParamUtil.getPassword());

        } catch (SQLException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return conn;
    }

    public static void closeConnection(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
